package com.ai.trickycards.utils

import com.ai.trickycards.entity.enumeration.PokerItem
import com.ai.trickycards.entity.enumeration.PokerRankEnum
import com.ai.trickycards.entity.enumeration.PokerSuitEnum

object PokerCalculate {
    /**
     * 生成剩余的未使用牌堆
     * @param excludeCards 需要排除的牌
     */
    fun generateRemainingCards(excludeCards: List<PokerItem>): List<PokerItem> {
        // 所有花色
        val pokerSuit = listOf(
            PokerSuitEnum.Spade,
            PokerSuitEnum.Heart,
            PokerSuitEnum.Club,
            PokerSuitEnum.Diamond
        )
        // 所有点数
        val pokerRanks = PokerRankEnum.entries.toTypedArray()

        val list = mutableListOf<PokerItem>()
        pokerSuit.forEach { suit ->
            pokerRanks.forEach { num ->
                if (!excludeCards.any { it.rank == num && it.suit == suit }) {
                    list.add(PokerItem(suit, num))
                }
            }
        }

        if (excludeCards.contains(PokerItem.joker())) {
            list.add(PokerItem.joker())
        }

        return list
    }

    /**
     * number模式下的所有的扑克
     */
    fun numberCards(): List<PokerItem> {
        // 所有花色
        val pokerSuit = listOf(
            PokerSuitEnum.Spade,
            PokerSuitEnum.Heart,
            PokerSuitEnum.Club,
            PokerSuitEnum.Diamond
        )
        // 所有点数
        val pokerRanks = listOf(
            PokerRankEnum.Rank2,
            PokerRankEnum.Rank3,
            PokerRankEnum.Rank4,
            PokerRankEnum.Rank5,
            PokerRankEnum.Rank6,
            PokerRankEnum.Rank7,
            PokerRankEnum.Rank8,
            PokerRankEnum.Rank9
        )

        val list = mutableListOf<PokerItem>()
        pokerSuit.forEach { suit ->
            pokerRanks.forEach { num ->
                list.add(PokerItem(suit, num))
            }
        }

        list.add(PokerItem.joker())

        return list
    }

    /**
     * royal模式下的所有的扑克
     */
    fun royalCards(): List<PokerItem> {
        // 所有花色
        val pokerSuit = listOf(
            PokerSuitEnum.Spade,
            PokerSuitEnum.Heart,
            PokerSuitEnum.Club,
            PokerSuitEnum.Diamond
        )
        // 所有点数
        val pokerRanks = listOf(
            PokerRankEnum.RankT,
            PokerRankEnum.RankJ,
            PokerRankEnum.RankQ,
            PokerRankEnum.RankK,
            PokerRankEnum.RankA
        )

        val list = mutableListOf<PokerItem>()
        pokerSuit.forEach { suit ->
            pokerRanks.forEach { num ->
                list.add(PokerItem(suit, num))
            }
        }

        list.add(PokerItem.joker())

        return list
    }

    /**
     * complex模式下的所有的扑克
     */
    fun complexCard() = generateRemainingCards(emptyList())

}